package cn.itcast.solr;

import cn.itcast.solr.pojo.Item;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;

import java.io.IOException;

public class SolrCreate {

    @Test
    public void testCreate() throws IOException, SolrServerException {

        // 创建solr服务对象, solr服务器的地址+core名称
        HttpSolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core2");

        // 初始化文档对象
        SolrInputDocument document = new SolrInputDocument();
        document.addField("id", "5");
        document.addField("title", "三星手机，爆炸神器");
        solrServer.add(document);
        // 提交
        solrServer.commit();
    }

    @Test
    public void testCreateBean() throws IOException, SolrServerException {

        // 创建solr服务对象, solr服务器的地址+core名称
        HttpSolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core2");

        Item item = new Item("11", "锤子手机，为情怀而生", 4999l);

        solrServer.addBean(item);
        // 提交
        solrServer.commit();
    }
}
